import { BasicColumn } from '@/components/Table';
import { FormSchema } from '@/components/Table';
import { useI18n } from '@/hooks/web/useI18n';

const { t } = useI18n();
export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
    width: 300,
  },
  {
    title: '编码',
    dataIndex: 'code',
    width: 100,
  },
  {
    title: '类型',
    dataIndex: 'orgType',
    width: 100,
    customRender: ({ text }) => {
      return text === 'org' ? '组织' : '部门';
    },
  },
  {
    title: t('排序'),
    dataIndex: 'sort',
    width: 150,
  },
  {
    title: t('创建时间'),
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: t('备注'),
    dataIndex: 'remark',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false,
  },
  {
    field: 'pid',
    label: '上级组织/部门',
    component: 'TreeSelect',

    componentProps: ({ formModel }) => {
      return {
        fieldNames: {
          label: 'name',
          key: 'id',
          value: 'id',
        },
        getPopupContainer: () => document.body,
      };
    },
    required: true,
  },
  {
    field: 'orgType',
    label: '组织部门类型',
    component: 'ApiSelect',
    defaultValue: 'org',
    componentProps: {
      dictCode: 'org_type',
    },
    required: true,
  },
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'code',
    label: '编码',
    component: 'Input',
    required: true,
  },

  {
    field: 'sort',
    label: t('排序'),
    component: 'InputNumber',
    required: true,
  },
  {
    label: t('备注'),
    field: 'remark',
    component: 'InputTextArea',
  },
];
